import React, { PureComponent } from 'react';
import { Carousel, Row, Col, List, Avatar, Card, Icon, Divider, message } from 'antd';
import axios from 'axios';
import './article.css';
export default class Article extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      data: [],
      token: sessionStorage.getItem('token')
    }
  }
  componentDidMount() {
    this.getArticle();
  }
  getArticle = () => {
    axios({
      method: 'post',
      url: "http://localhost:8080/article/selectById",
      data: { token: this.state.token, id: this.props.match.params.id }
    }).then((res) => {
      if (res.data.code == 200) {
        this.setState({ data: res.data.data });

      } else {
        message.error("获取文章失败")
        throw res;
      }
    }).catch((e) => {
      message.error("获取文章失败")
      throw e;
    });
  }
  render() {
    const card = this.state.data
    return (
      <div className="action" style={{ margin: '16px auto' }}>
        <Card>
          <h2 style={{ textAlign: 'center' }}>{card.title}</h2>
          <Divider />
          <p style={{ textIndent: '2rem', lineHeight: '1.5rem', margin: '16px auto', maxWidth: '720px' }}>{card.word || ''}</p>
        </Card>
      </div>
    );
  }
}